<template>
  <div class="app-container">
    <!--高级查询-->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="姓名" prop="studentname">
        <el-input
          v-model="queryParams.studentname"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="电话" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="性别" prop="sex">
        <el-select v-model="queryParams.sex" placeholder="请选择性别" clearable>
          <el-option
            v-for="dict in dict.type.sys_user_sex"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="班级" prop="classroom">
        <el-select v-model="queryParams.classroom" placeholder="请选择班级" clearable>
          <el-option
            v-for="dict in dict.type.sys_help_classroom"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="预约时间" prop="ordertime">
        <el-date-picker clearable
          v-model="queryParams.ordertime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择预约时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="问题类型" prop="problemId">
        <el-select v-model="queryParams.problemId" placeholder="请选择问题类型" clearable>
          <el-option
            v-for="dict in dict.type.student_help_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="帮扶老师" prop="techerId">
        <el-select v-model="queryParams.techerId" placeholder="请选择帮扶老师" clearable>
          <el-option
            v-for="dict in teachers"
            :key="dict.id"
            :label="dict.teachername"
            :value="dict.id"
          />
        </el-select>
      </el-form-item>
<!--      <el-form-item label="帮扶老师" prop="techerId">-->
<!--        <el-input-->
<!--          v-model="queryParams.techerId"-->
<!--          placeholder="请输入帮扶老师"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="帮扶状态" prop="state">
        <el-select v-model="queryParams.state" placeholder="请选择帮扶状态" clearable>
          <el-option
            v-for="dict in dict.type.student_help_states"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="完成时间" prop="outtime">
        <el-date-picker clearable
          v-model="queryParams.outtime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择完成时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!--功能  增删改导-->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['job:help:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['job:help:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['job:help:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['job:help:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="multiple"
          @click="batchTransfer"
          v-hasPermi="['job:transfer:add']"
        >移交</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="helpList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="编号" align="center" prop="id" width="60"/>
      <el-table-column label="姓名" align="center" prop="studentname" width="100"/>
      <el-table-column label="微信" align="center" prop="wechat" width="80"/>
      <el-table-column label="电话" align="center" prop="phone" width="120"/>
      <el-table-column label="班级" align="center" prop="classroom">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.student_help_class" :value="scope.row.classroom"/>
        </template>
      </el-table-column>
      <el-table-column label="预约时间" align="center" prop="ordertime" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.ordertime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="问题类型" align="center" prop="problemId">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.student_help_type" :value="scope.row.problemId"/>
        </template>
      </el-table-column>
      <el-table-column label="问题描述" align="center" prop="note" width="120"/>
<!--      <el-table-column label="帮扶老师" align="center" prop="techerId" />-->
      <el-table-column label="帮扶老师" align="center" prop="teacher.teachername" />
      <el-table-column label="帮扶状态" align="center" prop="state">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.student_help_status" :value="scope.row.state"/>
        </template>
      </el-table-column>
      <el-table-column label="老师备注" align="center" prop="teachernote" />
      <el-table-column label="完成时间" align="center" prop="outtime" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.outtime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['job:help:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="primary"
            plain
            icon="el-icon-star-off"
            @click="handleRemark(scope.row)"
            v-hasPermi="['job:student:remark']"
          >评价
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['job:help:remove']"
          >删除</el-button>

          <el-button
            v-if="scope.row.state===1 || scope.row.state===4"
            v-show="display"
            size="mini"
            type="success"
            icon="el-icon-cherry"
            @click="handleTransfer(scope.row)"
            v-hasPermi="['job:help:transfer']"
          >移交</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- ==============新增就业帮扶对话框 =========================-->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px" >
        <el-form-item label="姓名" prop="studentname">
          <el-input v-model="form.studentname" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="微信" prop="wechat">
          <el-input v-model="form.wechat" placeholder="请输入微信" />
        </el-form-item>
        <el-form-item label="电话" prop="phone">
          <el-input v-model="form.phone"  placeholder="请输入电话" />
        </el-form-item>
        <el-form-item label="班级" prop="classroom">
          <el-select v-model="form.classroom" placeholder="请选择班级">
            <el-option
              v-for="dict in dict.type.student_help_class"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="预约时间" prop="ordertime">
          <el-date-picker
            clearable
            v-model="form.ordertime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择预约时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="问题类型" prop="problemId">
          <el-select v-model="form.problemId" placeholder="请选择问题类型">
            <el-option
              v-for="dict in dict.type.student_help_type"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="问题描述" prop="note">
          <el-input v-model="form.note" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="帮扶老师" prop="techerId">
          <el-select  v-model="form.techerId" placeholder="请选择">
            <el-option
              v-for="item in teachers"
              :key="item.id"
              :label="item.teachername"
              :value="item.id">
              <span style="float: left">{{ item.teachername }}</span>
              <span style="float: right; color: #8492a6; font-size: 13px">{{ item.phone }}</span>
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="帮扶状态"  prop="state">
          <el-select v-model="form.state" placeholder="请选择帮扶状态">
            <el-option
              v-for="dict in dict.type.student_help_status"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>


    <!-- 修改就业帮扶对话框 -->
    <el-dialog :title="title" :visible.sync="upOpen" width="500px" append-to-body>
      <el-form ref="upForm" :model="upForm" :rules="rules" label-width="80px" >
        <el-form-item label="姓名" prop="studentname">
          <el-input v-model="upForm.studentname" disabled="disabled" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="微信" prop="wechat">
          <el-input v-model="upForm.wechat" disabled="disabled" placeholder="请输入微信" />
        </el-form-item>
        <el-form-item label="电话" prop="phone">
          <el-input v-model="upForm.phone" disabled="disabled"  placeholder="请输入电话" />
        </el-form-item>
        <el-form-item label="班级" prop="classroom">
          <el-select disabled="disabled" v-model="upForm.classroom" placeholder="请选择班级">
            <el-option
              v-for="dict in dict.type.student_help_class"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="预约时间" prop="ordertime">
          <el-date-picker
            disabled="disabled"
            clearable
            v-model="upForm.ordertime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择预约时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="问题类型" prop="problemId">
          <el-select disabled="disabled" v-model="upForm.problemId" placeholder="请选择问题类型">
            <el-option
              v-for="dict in dict.type.student_help_type"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="问题描述" prop="note">
          <el-input   v-model="upForm.note" type="textarea" placeholder="请输入内容" disabled="disabled"/>
        </el-form-item>
        <!--        <el-form-item label="帮扶老师" prop="techerId">-->
        <!--          <el-input v-model="form.techerId" placeholder="请输入帮扶老师" />-->
        <!--        </el-form-item>-->
        <el-form-item label="帮扶老师" prop="techerId">
          <el-select  disabled="disabled" v-model="upForm.techerId" placeholder="请选择">
            <el-option
              v-for="item in teachers"
              :key="item.id"
              :label="item.teachername"
              :value="item.id">
              <span style="float: left">{{ item.teachername }}</span>
              <span style="float: right; color: #8492a6; font-size: 13px">{{ item.phone }}</span>
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="帮扶状态"  prop="state">
          <el-select v-model="upForm.state" placeholder="请选择帮扶状态">
            <el-option
              v-for="dict in dict.type.student_help_status"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="老师备注" prop="teachernote">
          <el-input v-model="upForm.teachernote"  type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="完成时间" prop="outtime">
          <el-date-picker clearable
                          v-model="upForm.outtime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择完成时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="updateForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改帮扶评价管理对话框 -->
    <el-dialog :title="title" :visible.sync="open_remark" width="500px" append-to-body>
      <el-form ref="remark" :model="remark" :rules="rules_remark" label-width="80px">
        <el-form-item label="评分" prop="state">
          <el-select v-model="remark.state" placeholder="请选择评分">
            <el-option
              v-for="dict in dict.type.student_help_score"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="评价" prop="note">
          <el-input v-model="remark.note" type="textarea" placeholder="请输入内容" />
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitRemark">确 定</el-button>
        <el-button @click="cancelRemark">取 消</el-button>
      </div>
    </el-dialog>


    <!-- 移交对话框 接收人id +移交备注  -->
    <el-dialog :title="title" :visible.sync="transferOpen" width="500px" append-to-body>
      <el-form ref="transferForm" :model="transferForm" :rules="transferRules" label-width="80px" >
        <el-form-item label="移交给谁" prop="techerId">
          <el-select  v-model="transferForm.receiverid" placeholder="请选择">
            <el-option
              v-for="item in transferTeachers"
              :key="item.id"
              :label="item.teachername"
              :value="item.id">
              <span style="float: left">{{ item.teachername }}</span>
              <span style="float: right; color: #8492a6; font-size: 13px">{{ item.phone }}</span>
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="任务备注" prop="transferNote">
          <el-input v-model="transferForm.transfernote"  type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitTransfer">确 定</el-button>
        <el-button @click="cancelTransfer">取 消</el-button>
      </div>
    </el-dialog>


  </div>
</template>

<script>
import { listHelp, getHelp, delHelp, addHelp, updateHelp } from "@/api/job/help";
import { listTeacher,listTransferTeacher  } from "@/api/job/teacher";
import {addTransfer, updateTransfer} from "@/api/job/transfer";
import {addRemark} from "@/api/job/remark";

export default {
  name: "Help",
  dicts: ['student_help_class', 'student_help_type', 'student_help_status', 'student_help_score'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 就业帮扶表格数据
      helpList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示弹出层
      upOpen: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        studentname: null,
        phone: null,
        sex: null,
        classroom: null,
        ordertime: null,
        problemId: null,
        techerId: null,
        state: null,
        outtime: null
      },
      // 表单参数
      form: {},
      // 表单参数
      upForm: {},
      // 表单校验
      rules: {
        studentname: [
          { required: true, message: "姓名不能为空", trigger: "blur" }
        ],
        ordertime: [
          { required: true, message: "预约时间不能为空", trigger: "blur" }
        ],
        problemId: [
          { required: true, message: "问题类型不能为空", trigger: "change" }
        ],
        note: [
          { required: true, message: "问题描述不能为空", trigger: "blur" }
        ],
        techerId: [
          { required: true, message: "帮扶老师不能为空", trigger: "blur" }
        ],
      },
      //所有老师-下拉框
      teachers:[],
      //评价
      // 是否显示弹出层
      open_remark: false,
      // 表单参数
      remark: {},
      // 表单校验
      rules_remark: {
        state: [
          { required: true, message: "评分不能为空", trigger: "change" }
        ],
        helpId: [
          { required: true, message: "帮扶id不能为空", trigger: "blur" }
        ],
        stuname: [
          { required: true, message: "帮扶学生不能为空", trigger: "blur" }
        ],
        tename: [
          { required: true, message: "帮扶老师不能为空", trigger: "blur" }
        ],
        helpstate: [
          { required: true, message: "帮扶状态不能为空", trigger: "change" }
        ],
        pronote: [
          { required: true, message: "问题描述不能为空", trigger: "blur" }
        ]
      },

      //移交老师-下拉框
      transferTeachers:[],
      //移交按钮的显示
      display:true,
      // 是否显示弹出层
      transferOpen: false,
      // 表单参数
      transferForm: {},
      // 表单校验
      transferRules: {
        transfername: [
          { required: true, message: "移交人不能为空", trigger: "blur" }
        ],
        receiverid: [
          { required: true, message: "接受人id不能为空", trigger: "blur" }
        ],
        receivername: [
          { required: true, message: "接收人不能为空", trigger: "blur" }
        ],
        transfertime: [
          { required: true, message: "移交时间不能为空", trigger: "blur" }
        ],
        helpname: [
          { required: true, message: "帮扶任务名不能为空", trigger: "blur" }
        ],
        transfernote: [
          { required: true, message: "移交备注不能为空", trigger: "blur" }
        ],
        helpid: [
          { required: true, message: "帮扶id不能为空", trigger: "blur" }
        ]
      },
      //批量移交的判断参数
      batchJudge:true,
    };

  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询就业帮扶列表 */
    getList() {
      this.loading = true;
      listHelp(this.queryParams).then(response => {
        this.helpList = response.rows;
        //当帮扶状态为1的时候，才展示移交按钮   rows
        // console.log(this.helpList)
        /*this.helpList.forEach(help => {
          console.log(help.state)
         if (help.state==1){
           this.display=true;
         }else {
           this.display=false;
         }
        })*/

        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.upOpen = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        studentname: null,
        wechat: null,
        phone: null,
        sex: null,
        classroom: null,
        ordertime: null,
        problemId: null,
        note: null,
        techerId: null,
        state: null,
        teachernote: null,
        outtime: null
      };
      this.resetForm("form");
    },// 表单重置
    reset2() {
      this.upForm = {
        id: null,
        studentname: null,
        wechat: null,
        phone: null,
        sex: null,
        classroom: null,
        ordertime: null,
        problemId: null,
        note: null,
        techerId: null,
        state: null,
        teachernote: null,
        outtime: null
      };
      this.resetForm("upForm");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.reset2();
      this.open = true;
      this.title = "添加就业帮扶";
      this.findTeachers();
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset2();
      const id = row.id || this.ids
      getHelp(id).then(response => {
        this.upForm = response.data;
        this.upOpen = true;
        this.title = "修改就业帮扶";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateHelp(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addHelp(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    updateForm() {
      this.$refs["upForm"].validate(valid => {
        if (valid) {
          if (this.upForm.id != null) {
            updateHelp(this.upForm).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.upOpen = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除就业帮扶编号为"' + ids + '"的数据项？').then(function() {
        return delHelp(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('job/help/export', {
        ...this.queryParams
      }, `help_${new Date().getTime()}.xlsx`)
    },
    /** 查询所有老师*/
    findTeachers(){
      listTeacher().then(response => {
        this.teachers = response.rows;
      });
    },

    // ===================移交相关方法===========================

    /** 查询移交老师*/
    findTransferTeacher(id){
      listTransferTeacher(id).then(response => {
        this.transferTeachers = response.rows;
      });
    },

    // 移交取消按钮
    cancelTransfer() {
      this.transferOpen = false;
      this.resetTransfer();
    },
    // 移交表单重置
    resetTransfer() {
      this.transferForm = {
        id: null,
        transferid: null,
        transfername: null,
        receiverid: null,
        receivername: null,
        transfertime: null,
        helpname: null,
        transfernote: null,
        helpid: null,

      };
      this.resetForm("transferForm");
    },



    /**
     * 移交按钮点击操作
     */
    handleTransfer(row){

      // 获取当前登录人
      var username = this.$store.state.user.name;
      var tename=row.teacher.teachername
      // console.log(tename)
      //当前登录人不是该条数据的老师
      if (tename !== username){
        alert("您不是该学生的帮扶老师，无权移交！")
      }else {
        this.title = "添加帮扶移交";
        //打开模态框
        this.transferOpen=true;
        //获取移交老师列表
        this.findTransferTeacher(row.techerId)

        //当前行的id==帮扶id==移交的helpid
        this.transferForm.helpid=row.id
        //当前行的老师id==移交人id
        this.transferForm.transferid=row.techerId
        //当前行的老师名字==移交人名字
        this.transferForm.transfername=row.teacher.teachername
        //移交任务名=="帮扶任务移交,学生："+当前行学生名字
        this.transferForm.helpname="帮扶任务移交,学生："+row.studentname

      }

    },

    /**
     * 保存移交
     */
    submitTransfer(){
      // debugger
      this.$refs["transferForm"].validate(valid => {
        if (valid) {
            addTransfer(this.transferForm).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.transferOpen = false;
              this.getList();
            });

        }
      });
    },

    /**
     * 批量移交
     * @param row
     */
    batchTransfer(){
      const ids =  this.ids;
      try {
        //遍历ids
        ids.forEach(id=>{
          //获取每个id对应的帮扶信息
          getHelp(id).then(response => {
            //如果该信息的状态!=1
            if (response.data.state !== 1){
              //提示用户重新选择
              this.$modal.msgError("您选择了非待理处状态的数据,请重新选择!");
              this.batchJudge=false;
              throw Error("请重新选择非待理处状态的数据!")
            }
          })
        })
      }catch (e){
      }finally {
        if (!this.batchJudge){
          this.$modal.confirm('是否确认移交就业帮扶编号为"' + ids + '"的数据项？').then(function() {
            ids.forEach(id=>{
              return addTransfer(id);
            })
          }).then(() => {
            this.getList();
            this.$modal.msgSuccess("移交成功");
          }).catch(() => {});
        }
      }
      },
    // ================ 评价相关方法 =================
    /**
     * 评价按钮
     * @param row
     */
    handleRemark(row){
      this.open_remark = true;
      this.remark.helpId=row.problemId;
      this.remark.stuname=row.studentname;
      this.remark.tename=row.teacher.teachername;
      this.remark.helpstate=row.state;
      this.remark.pronote=row.note;
      this.title = "添加帮扶评价";
    },
    /**
     * 评价表单重置
     */
    resetRemark() {
      this.remark = {
        id: null,
        state: null,
        note: null,
        helpId: null,
        stuname: null,
        tename: null,
        helpstate: null,
        pronote: null
      };
      this.resetForm("remark");
    },

    /**
     * 取消
     */
    cancelRemark() {
      this.open_remark = false;
      this.resetRemark();
    },

    /**
     * 提交评价
     */
    submitRemark(){
      this.$refs["remark"].validate(valid => {
        if (valid) {
          addRemark(this.remark).then(response => {
            this.$modal.msgSuccess("新增成功");
            this.open_remark = false;
            this.resetRemark();
          });
        }
      });
    },
  },
  mounted() {
    this.findTeachers();
    // 获取当前登录人
    const username = this.$store.state.user.name;
    console.log(username)
  }
};
</script>
